package com.oms.app.user.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.oms.app.user.dao.IRoleDAO;
import com.oms.app.user.model.Role;
import com.oms.core.dao.impl.GeneralDAO;

/**
 * controller
 * @author wtj
 * @date Sep 10, 2012  10:14:39 PM
 */

public class RoleDAOImpl extends GeneralDAO<Object, String> implements IRoleDAO {

	@Override
	public List getRoleList(HttpServletRequest request) {
		return this.queryForList("getAll",new HashMap<String, String>());
	}

	@Override
	public int delete(String primaryKey) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Object get(String primaryKey) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean saveOrUpdateRole(Role roleForm) {
		try {
			this.insert(roleForm);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	@Override
	public boolean deleteRole(String PK) {
		try {
			this.delete("delete", PK);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	@Override
	public List getGroupOfRole(Map map) {
		return this.queryForList("getGroupOfRole",map);
	}

	@Override
	public List getUserOfRole(Map map) {
		return this.queryForList("getUserOfRole",map);
	}

	@Override
	public boolean isRoleModule(Map map) {
		int ct = this.getCount("isRoleModule", map);
		return (ct > 0);
	}

	@Override
	public boolean roleAddModule(Map map) {
		this.insert("insertRoleModule", map);
		return false;
	}

	@Override
	public boolean delRoleModule(Map map) {
		this.delete("delRoleModule", map);
		return false;
	}
	
	@Override
	public Role getShopManagerRole() {
		return (Role) this.queryForObject("getShopManagerRole", null);
	}
}
